<?php

class NavigationView
{
	private static $Page = "Page";
	private static $TopicID ="TopicID";
	private static $RegisterURL = "RegisterPage";
		
	public static function isViewingRegisterForm()
	{
		if(isset($_GET[self::$Page]) &&
				 $_GET[self::$Page] == self::$RegisterURL)
		{
			return TRUE;
		}
		else
		{
			return FALSE;
		}
	}
	
	public static function isViewingTopic()
	{
		if(isset($_GET[self::$TopicID]) == TRUE)
		{
			return TRUE;
		}
		else
		{
			return FALSE;
		}
	}		
	
	public static function getRegisterLink()
	{
		return "?" . self::$Page . "=" . self::$RegisterURL;
	}
	
	public static function getTopicLink(Topic $topic)
	{
		return "?" . self::$TopicID . "=" . $topic->getId();
	}	

	public static function getSelectedTopic(TopicList $topicList)
	{
		if(isset($_GET[self::$TopicID]) == TRUE)
		{
			$urlId = $_GET[self::$TopicID];
			
			//Försäkrar att id:t är en integer.
			if($urlId != 0 && intval($urlId) == 0)
			{
				throw new Exception("URL called with invalid format");
			}
			else
			{
				$topicId = intval($urlId);	
				
				return $topicList->getTopic($topicId);
			}

		}
		else
		{
			throw new Exception("getSelectedTopic was called while not viewing a topic");
		}
		

	}			
	
}

?>